package cn.itcast.n4_共享模型_管程;

import lombok.extern.slf4j.Slf4j;

import static cn.itcast.util.Sleeper.sleep;

/**
 * @program: juc
 * @description:
 * @author: flyduck
 * @create: 2024-09-27 16:54
 **/
@Slf4j(topic = "c.Test23_sleep和wait的区别_sleep不释放锁_wait释放锁")
public class Test23_sleep和wait的区别_sleep不释放锁_wait释放锁 {

    static final Object lock = new Object();//加final保证synchronized锁住的同一个对象

    public static void main(String[] args) {
        new Thread(() -> {
            synchronized (lock){
                log.debug("获取到锁了");
                try {
                    //Thread.sleep(20000);
                    lock.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        },"t1").start();

        sleep(1);
        synchronized (lock) {
            log.debug("获取到锁了");
        }
    }
}
